package com.agree.util.excel.handlers.mapping;

import com.agree.util.excel.entity.TableInfo;
import com.agree.util.excel.enums.GetParamsType;
import com.agree.util.excel.enums.MappingConfig;
import com.agree.util.excel.enums.MappingType;
import com.agree.util.excel.entity.InterfaceColMapEntity;

import java.io.IOException;
import java.util.List;

/**
 * Created by wangmu on 2017/12/4.
 */
public class AddMappingHandler extends MappingHandler {


    public AddMappingHandler(MappingConfig mappingConfig) {
        super(mappingConfig);
    }

    @Override
    public List<InterfaceColMapEntity> mapProperties(TableInfo tableInfo) throws IllegalAccessException, InstantiationException, IOException {
        this.configure(tableInfo);
        InterfaceColMapEntity reqHeader = getReqHeader(tableInfo);
        List<InterfaceColMapEntity> reqParams = getReqParams(tableInfo);
        reqParams.add(0,reqHeader);
        insertOrderNum(reqParams);
        return reqParams;
    }

    @Override
    protected MappingType getType() {
        return MappingType.SIMPLE_ADD;
    }

    @Override
    protected void configure(TableInfo source) throws InstantiationException, IllegalAccessException, IOException {
        super.configure(source);
        startMapping().reqParams().anyColumn(GetParamsType.ALL,source).everyone().setMsgtypeid(mappingConfig.getTranCode()+".req").setMsgtypename(mappingConfig.getComment() == null ? source.getComment()+getType().getValue() : mappingConfig.getComment())
                .setColname("/ReqInfo/" + "#{humpName}").setColdesc("#{comment}").setColflag("F").setColtype("TextString").setCollength("#{maxIntegerLength}")
                .setColmapname("/#{humpName}").end();
    }
}
